import { proxy, useSnapshot } from '@umijs/max';

const state = {
  userId: '',
  formData: {
    _id: undefined,
    account: undefined,
    password: undefined,
    shoppingCartId: undefined,
    created: undefined,
  },
};

const actions = {
  setUserId(id: string) {
    loginState.userId = id;
    console.warn(loginState.userId);
  },
  setAccount(data: any) {
    loginState.formData = data;
  },
};

export const loginState: typeof state = proxy(state);
export const useLoginState = () => {
  const state = useSnapshot(loginState);
  return state;
};
export const loginActions = actions;
